home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / FilmWP (PL).ifs < prev    next >
Encoding:
Text File  |  2004-11-12  |  18.5 KB  |  517 lines

  1. // GETINFO SCRIPTING
  2. // Film.WP (PL) info by îwistak & picture by Goster
  3.  
  4. (***************************************************
  5.  *   Movie information & picture importation       *
  6.  *    script for http://film.wp.pl                 *
  7.  *           (c) 2004 îwistak                 *
  8.  *           (Picture by Goster)                        *    
  9.  *                                                 *
  10.  *      partialy based on filmweb script           *
  11.  *          by Piotr Kardasz, Adma's               *
  12.  *                                                 *
  13.  *  For use with Ant Movie Catalog 3.4.3           *
  14.  *  www.antp.be/software/moviecatalog              *
  15.  *                                                 *
  16.  *  This program is free software; you can         *
  17.  *  redistribute it and/or modify it under the     *
  18.  *  terms of the GNU General Public License as     *
  19.  *  published by the Free Software Foundation;     *
  20.  *  either version 2 of the License, or (at your   *
  21.  *  option) any later version.                     *
  22.  ***************************************************)
  23.  
  24. program FilmWP;
  25. var
  26.   MovieName, adres: string;
  27.   Link, id: string;
  28.  
  29. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  30.   var
  31.   i: Integer;
  32.   begin
  33.   result := -1;
  34.   if StartAt < 0 then
  35.     StartAt := 0;
  36.   for i := StartAt to List.Count-1 do
  37.     if Pos(Pattern, List.GetString(i)) <> 0 then
  38.       begin
  39.       result := i;
  40.       Break;
  41.       end;
  42.   end;
  43.  
  44. procedure DecodeHTML(var Value: String);
  45.   var
  46.   FullValue, CharCode: String;
  47.   Counter: Integer;
  48.   begin
  49.   if Value <> '' then begin
  50.     FullValue := '';
  51.     Counter := 1;
  52.     repeat
  53.       if StrGet(Value, Counter) <> '&' then
  54.         begin
  55.         CharCode := copy(Value, Counter, 1);
  56.         case CharCode of
  57.           '▒': CharCode := '╣';
  58.           '╢': CharCode := '£';
  59.           'í': CharCode := 'Ñ';
  60.           '╝': CharCode := 'ƒ';
  61.           'ª': CharCode := 'î';
  62.           '¼': CharCode := 'Å';
  63.           end;
  64.         FullValue := FullValue + CharCode;
  65.         Counter := Counter + 1;
  66.         end
  67.       else
  68.         begin
  69.         CharCode := copy(Value, Counter, 7);
  70.         case CharCode of
  71.           'ą': FullValue := FullValue + '╣';
  72.           'ć': FullValue := FullValue + 'µ';
  73.           'ę': FullValue := FullValue + 'Ω';
  74.           'ł': FullValue := FullValue + '│';
  75.           'ń': FullValue := FullValue + '±';
  76.           'ó': FullValue := FullValue + '≤';
  77.           'ś': FullValue := FullValue + '£';
  78.           'ź': FullValue := FullValue + 'ƒ';
  79.           'ż': FullValue := FullValue + '┐';
  80.           'Ą': FullValue := FullValue + 'Ñ';
  81.           'Ć': FullValue := FullValue + '╞';
  82.           'Ę': FullValue := FullValue + '╩';
  83.           'Ł': FullValue := FullValue + 'ú';
  84.           'Ń': FullValue := FullValue + '╤';
  85.           'Ó': FullValue := FullValue + '╙';
  86.           'Ś': FullValue := FullValue + 'î';
  87.           'Ź': FullValue := FullValue + 'Å';
  88.           'Ż': FullValue := FullValue + '»';
  89.           'Š': FullValue := FullValue + ' ';
  90.           'š': FullValue := FullValue + 'í';
  91.           'Ţ': FullValue := FullValue + 'í';
  92.           'ţ': FullValue := FullValue + 'ú';
  93.           'Ť': FullValue := FullValue + 'ñ';
  94.           'ť': FullValue := FullValue + 'Ñ';
  95.           'Ŧ': FullValue := FullValue + 'î';
  96.           'ŧ': FullValue := FullValue + 'º';
  97.           'Ũ': FullValue := FullValue + '¿';
  98.           'ũ': FullValue := FullValue + '⌐';
  99.           'Ű': FullValue := FullValue + '¬';
  100.           'ű': FullValue := FullValue + '½';
  101.           'Ų': FullValue := FullValue + '¼';
  102.           'ų': FullValue := FullValue + '¡';
  103.           'Ŵ': FullValue := FullValue + '«';
  104.           'ŵ': FullValue := FullValue + '»';
  105.           'Ŷ': FullValue := FullValue + '░';
  106.           'ŷ': FullValue := FullValue + '▒';
  107.           'Ÿ': FullValue := FullValue + '▓';
  108.           'ƀ': FullValue := FullValue + '┤';
  109.           'Ɓ': FullValue := FullValue + '╡';
  110.           'Ƃ': FullValue := FullValue + '╢';
  111.           'ƃ': FullValue := FullValue + '╖';
  112.           'Ƅ': FullValue := FullValue + '╕';
  113.           'ƅ': FullValue := FullValue + '╣';
  114.           'Ɔ': FullValue := FullValue + '║';
  115.           'Ƈ': FullValue := FullValue + '╗';
  116.           'ƈ': FullValue := FullValue + '╝';
  117.           'Ɖ': FullValue := FullValue + '╜';
  118.           'Ɛ': FullValue := FullValue + '╛';
  119.           'Ƒ': FullValue := FullValue + '┐';
  120.           'ƒ': FullValue := FullValue + '└';
  121.           'Ɠ': FullValue := FullValue + '┴';
  122.           'Ɣ': FullValue := FullValue + '┬';
  123.           'ƕ': FullValue := FullValue + '├';
  124.           'Ɩ': FullValue := FullValue + '─';
  125.           'Ɨ': FullValue := FullValue + '┼';
  126.           'Ƙ': FullValue := FullValue + '╞';
  127.           'ƙ': FullValue := FullValue + '╟';
  128.           'Ȁ': FullValue := FullValue + '╚';
  129.           'ȁ': FullValue := FullValue + '╔';
  130.           'Ȃ': FullValue := FullValue + '╩';
  131.           'ȃ': FullValue := FullValue + '╦';
  132.           'Ȅ': FullValue := FullValue + '╠';
  133.           'ȅ': FullValue := FullValue + '═';
  134.           'Ȇ': FullValue := FullValue + '╬';
  135.           'ȇ': FullValue := FullValue + '╧';
  136.           'Ȉ': FullValue := FullValue + '╨';
  137.           'ȉ': FullValue := FullValue + '╤';
  138.           'Ȑ': FullValue := FullValue + '╥';
  139.           'ȑ': FullValue := FullValue + '╙';
  140.           'Ȓ': FullValue := FullValue + '╘';
  141.           'ȓ': FullValue := FullValue + '╒';
  142.           'Ȕ': FullValue := FullValue + '╓';
  143.           'ȕ': FullValue := FullValue + '╫';
  144.           'Ȗ': FullValue := FullValue + '╪';
  145.           'ȗ': FullValue := FullValue + '┘';
  146.           'Ș': FullValue := FullValue + '┌';
  147.           'ș': FullValue := FullValue + '█';
  148.           'Ƞ': FullValue := FullValue + '▄';
  149.           'ȡ': FullValue := FullValue + '▌';
  150.           'Ȣ': FullValue := FullValue + '▐';
  151.           'ȣ': FullValue := FullValue + '▀';
  152.           'Ȥ': FullValue := FullValue + 'α';
  153.           'ȥ': FullValue := FullValue + 'ß';
  154.           'Ȧ': FullValue := FullValue + 'Γ';
  155.           'ȧ': FullValue := FullValue + 'π';
  156.           'Ȩ': FullValue := FullValue + 'Σ';
  157.           'ȩ': FullValue := FullValue + 'σ';
  158.           'Ȱ': FullValue := FullValue + 'µ';
  159.           'ȱ': FullValue := FullValue + 'τ';
  160.           'Ȳ': FullValue := FullValue + 'Φ';
  161.           'ȳ': FullValue := FullValue + 'Θ';
  162.           'ȴ': FullValue := FullValue + 'Ω';
  163.           'ȵ': FullValue := FullValue + 'δ';
  164.           'ȶ': FullValue := FullValue + '∞';
  165.           'ȷ': FullValue := FullValue + 'φ';
  166.           'ȸ': FullValue := FullValue + 'ε';
  167.           'ȹ': FullValue := FullValue + '∩';
  168.           'ɀ': FullValue := FullValue + '≡';
  169.           'Ɂ': FullValue := FullValue + '±';
  170.           'ɂ': FullValue := FullValue + '≥';
  171.           'Ƀ': FullValue := FullValue + '≤';
  172.           'Ʉ': FullValue := FullValue + '⌠';
  173.           'Ʌ': FullValue := FullValue + '⌡';
  174.           'Ɇ': FullValue := FullValue + '÷';
  175.           'ɇ': FullValue := FullValue + '≈';
  176.           'Ɉ': FullValue := FullValue + '°';
  177.           'ɉ': FullValue := FullValue + '∙';
  178.           'ɐ': FullValue := FullValue + '·';
  179.           'ɑ': FullValue := FullValue + '√';
  180.           'ɒ': FullValue := FullValue + 'ⁿ';
  181.           'ɓ': FullValue := FullValue + '²';
  182.           'ɔ': FullValue := FullValue + '■';
  183.           'ɕ': FullValue := FullValue + ' ';
  184.           '&#x%DF;': FullValue := FullValue + '▀';
  185.           '4': FullValue := FullValue + '"';
  186.           '–': FullValue := FullValue + '-';
  187.           '‘': FullValue := FullValue + '"';
  188.           '’': FullValue := FullValue + '"';
  189.           '“': FullValue := FullValue + '"';
  190.           '”': FullValue := FullValue + '"';
  191.           '„': FullValue := FullValue + '"';
  192.           else
  193.             FullValue := FullValue + CharCode;
  194.           end;
  195.         Counter := Counter + 7;
  196.       end;
  197.     until Counter > Length(Value);
  198.     HTMLDecode(FullValue);
  199.     Value := FullValue;
  200.     end
  201.   end;
  202.  
  203.  
  204. function extractLineText(Line: string; startToken: string; endToken: string): string;
  205.   var
  206.   StartPos: Integer;
  207.   token: string;
  208.   begin
  209.   StartPos := pos(startToken, Line) + Length(startToken);
  210.   Line := copy(Line, StartPos, Length(Line) - StartPos +1);
  211.   Line := copy(Line, 1, Pos(endToken, Line)-1);
  212.   HTMLRemoveTags(Line);
  213.   DecodeHTML(Line);
  214.   extractLineText := Trim(Line);
  215.   end;
  216.  
  217. function extractText(Page: TStringList; startToken: string; endToken: string; startPos: Integer): string;
  218.   var
  219.   Line: String;
  220.   begin
  221.   Line := copy(Page.Text, startPos, Length(Page.Text)-startPos);
  222.   StartPos := pos(startToken, Line);
  223.   if (StartPos > 0) then
  224.     begin
  225.     StartPos := pos(startToken, Line) + Length(startToken);
  226.     //aby zepewniµ obs│ugΩ przypadku, gdy endToken wystΩpuje tak┐e przed startToken
  227.     Line := copy(Line, StartPos, Length(Page.Text) - StartPos +1);
  228.     Line := copy(Line, 1, Pos(endToken, Line)-1);
  229.     HTMLRemoveTags(Line);
  230.     DecodeHTML(Line);
  231.     Line := Trim(Line);
  232.     Line := StringReplace(Line, #13#10, '');
  233.     end
  234.   else
  235.     Line := '';
  236.  
  237.   extractText := Line;
  238.   end;
  239.  
  240. function ExtractMovieAddress(Line: string): String ;
  241.   var
  242.   MovieAddress: string;
  243.   StartPos: Integer;
  244.   begin
  245.   StartPos := Pos('<a href=', Line);
  246.   if (StartPos > 0) then
  247.     begin
  248.     MovieAddress := copy(Line, StartPos, Length(Line)-StartPos);
  249.     MovieAddress := copy(MovieAddress, 10, Pos('">', MovieAddress)-10);
  250.     end;
  251.   extractMovieAddress := MovieAddress;
  252. end;
  253.  
  254. procedure AddMoviesTitles(Page: TStringList);
  255.   var
  256.   LineNr: Integer;
  257.   Line: string;
  258.   MovieTitle, MovieAddress: string;
  259.   StartPos: Integer;
  260.   begin
  261.   //NajczΩ£ciej szukane
  262.   LineNr := FindLine('szukane:', Page, 0);
  263.   if LineNr > -1 then
  264.   begin
  265.     PickTreeAdd('NajczΩ£ciej szukane:', '');
  266.     MovieTitle := extractLineText(Page.GetString(LineNr+16), '<i>', '</i>');
  267.     if (MovieTitle<>'') then
  268.       MovieTitle := ' (' + MovieTitle + ')';
  269.     MovieTitle := extractLineText(Page.GetString(LineNr+15), '<b>', '</a>')+MovieTitle;
  270.  
  271.     Line := Page.GetString(LineNr+15);
  272.     MovieAddress := extractMovieAddress(Line);
  273.     PickTreeAdd(MovieTitle, MovieAddress);
  274.  
  275.     //Znalezionych
  276.     LineNr := FindLine('Znalezionych:', Page, LineNr);
  277.     Line := Page.GetString(LineNr);
  278.     //Sprawdzamy ile WP znalaz│o pozycji
  279.     StartPos := pos('<b>', Line)+3;
  280.     Line := copy(Line, StartPos, pos('</b>', Line)-StartPos);
  281.     if (StrToInt(Line, 0)>1) then
  282.       begin
  283.       PickTreeAdd('Znalezione ('+Line+'):', '');
  284.       LineNr := LineNr+6;
  285.       repeat
  286.         Line := Page.GetString(LineNr);
  287.         if (pos('span class', Line)>0) then
  288.           begin
  289.           MovieTitle := extractLineText(Page.GetString(LineNr+1), '<i>', '</i>');
  290.           if (MovieTitle<>'') then
  291.             MovieTitle := ' (' + MovieTitle + ')';
  292.           MovieTitle := extractLineText(Page.GetString(LineNr), ' ', '</a>')+MovieTitle;
  293.           MovieAddress := ExtractMovieAddress(Line);
  294.           PickTreeAdd(MovieTitle, MovieAddress);
  295.           end
  296.         else if (pos('znalezione pozycje', Line)>0) then
  297.           begin
  298.           MovieAddress := ExtractMovieAddress(Line);
  299.           PickTreeAdd('Poka┐ wszystkie pozycje...' , MovieAddress);
  300.           end;        
  301.         LineNr := LineNr+1;
  302.       until Pos('</table>', Line) > 0;
  303.       end;
  304.     end;
  305.   end;
  306.  
  307. procedure AnalyzePage(Address: string; PostQuery: string);
  308.   var
  309.   Page: TStringList;
  310.   
  311.   begin
  312.   adres := address;
  313.   Page := TStringList.Create;
  314.   if (PostQuery <> '') then
  315.     Page.Text := PostPage(Address, PostQuery)
  316.   else
  317.     Page.Text := GetPage(Address);
  318.   Link := Address;
  319.   if pos('Podyskutuj na Forum', Page.Text) > 0 then
  320.     AnalyzeMoviePage(Page)
  321.   else if pos('Znalezionych:', Page.Text) > 0 then
  322.     begin
  323.     PickTreeClear;
  324.     AddMoviesTitles(Page);
  325.     if PickTreeExec(Address) then
  326.       AnalyzePage(Address, '');
  327.     end
  328.     else
  329.      begin
  330.      DecodeHTML(MovieName);
  331.      ShowMessage('Nie znaleziono ┐adnego filmu spe│niaj╣cego kryteria: "'+MovieName+'".');
  332.      end
  333.  
  334.   Page.Free;
  335.   end;
  336.  
  337. procedure AnalyzeMoviePage(Page: TStringList);
  338.   var
  339.   Line, Obsada, OrgLine, linia, tytul: string;
  340.   LineNr, licznik, pozycja, pozycja2: Integer;
  341.   StartPos, endPos: Integer;
  342.    stronka: TStringList;
  343.   
  344.   begin
  345.   // Tytu│ polski & Rok produkcji
  346.   Line := extractText(Page, '<b class="ti">', '</b>', 0);
  347.   //czasami wp dodaje rok produkcji do lini z tytu│em
  348.   StartPos := Pos('(', Line);
  349.   if (StartPos > 0) then
  350.     begin
  351.     SetField(fieldYear, Copy(Line, StartPos+1, 4));
  352.     Line := Copy(Line, 0, StartPos-1);
  353.     end
  354.   setField(fieldTranslatedTitle, Line);
  355.  
  356.   // Tytu│ oryginalny
  357.   Line := extractText(Page, '<i class="ti" id="gr">', '</i>', 0);
  358.   //czasami wp w linii, gdzie jest polski tytu│ umieszcza angielski, polskiego nie za│╣czaj╣c wog≤le...
  359.   if ((Pos('<i class="ti" id="gr">', Page.Text) > Pos('Tw≤rcy:', Page.Text)) or (Line = '')) then
  360.     begin
  361.     Line := getField(fieldTranslatedTitle);
  362.     setField(fieldTranslatedTitle, '');
  363.     end
  364.   setField(fieldOriginalTitle, Line);
  365.  
  366.   // Kategoria
  367.   setField(fieldCategory, extractText(Page, '<b>Gatunek:</b>', '<br>', 0));
  368.  
  369.   // Kraj
  370.   setField(fieldCountry, extractText(Page, '<b>Kraj:</b>', '<br>', 0));
  371.   
  372.   // Czas trwania
  373.   setField(fieldLength, extractText(Page, '<b>Czas trwania:</b>', 'min', 0));
  374.  
  375.   // Rok produkcji
  376. //  Line := extractText(Page, '<b>Premiera kinowa:</b>', '<br>', 0);
  377. //  Line := copy(Line, 1, 4);
  378. //  SetField(fieldYear, Line);
  379.  
  380.   // Ocena
  381.   Line := extractText(Page, 'Ocena internaut≤w:', '</b>', 0);
  382.   if (Line <> '') then
  383.     SetField(fieldRating, IntToStr(Round(StrToFloat(Line))));
  384.  
  385.   // Producent
  386.   //brak
  387.  
  388.   // Re┐yseria
  389.   SetField(fieldDirector, extractText(Page, '<b>Re┐yseria:</b>', '<br>', 0));
  390.  
  391.   // Obsada
  392.   LineNr := FindLine('<b>Obsada:</b>', Page, 0)+1;
  393.   if (LineNr>0) then
  394.     begin
  395.     Obsada := '';
  396.     Line := Page.GetString(LineNr);
  397.     while (Pos('<div align="right">', Line) = 0) do
  398.       begin
  399.       if (Obsada<>'') then
  400.         Obsada := Obsada + ', ';
  401.       HTMLRemoveTags(Line);
  402.       DecodeHTML(Line);
  403.       if (Pos('..... ', Line) > 0) then
  404.         begin
  405.         Line := StringReplace(Line, '..... ', '(jako ');
  406.         Line := Line + ')';
  407.         end;
  408.       Obsada := Obsada + Line;
  409.       LineNr := LineNr+1;
  410.       Line := Page.GetString(LineNr);
  411.       end;
  412.     SetField(fieldActors, Obsada);
  413.     end;
  414.  
  415.   // Czas trwania
  416.   //brak
  417.  
  418.   // Opis filmu
  419.   StartPos := Pos('<b class="ti" id="or">Opis:</b>', Page.Text);
  420.   if (StartPos > 0) then
  421.     SetField(fieldDescription, extractText(Page, '<span id="mi">', '</span>', StartPos));
  422.  
  423.   //Komentarze
  424.   StartPos := Pos('<b class="ti" id="or">Recenzje:', Page.Text);
  425.   //czasami zamiast 'Recenzje' jest 'Opinie'
  426.   if (StartPos = 0) then
  427.     StartPos := Pos('<b class="ti" id="or">Opinie:', Page.Text);
  428.  // if (StartPos > 0) then
  429.    // SetField(fieldComments, extractText(Page, '<span id="mi">', '</span>', StartPos));
  430.  
  431.   //URL
  432.   setField(fieldURL, Link);
  433.   
  434.   //Foto 
  435.   //pobranie strony z galeri╣
  436.   stronka := TStringList.Create;
  437.   startPos := pos('id=', adres);
  438.   endPos := pos('&h=', adres);
  439.   id := copy(adres, startPos + 3, endPos - startPos - 3);
  440.   link := 'http://film.wp.pl/film_foto.html?id=' + id + '&m=plakat';
  441.   stronka.Text := GetPage(link);
  442.   PickTreeClear;
  443.   PickTreeAdd('Wybierz ZdjΩcie','');
  444.   licznik := 0;
  445.   pozycja := FindLine('<img src="http://film.wp.pl/f/foto/small/', stronka, 0);
  446.   pozycja2 := FindLine('galeria: ', stronka, pozycja + 1);
  447.   repeat
  448.    begin
  449.    linia := stronka.GetString(pozycja);
  450.    startPos := pos('<img src="http://film.wp.pl/f/foto/small/', linia);
  451.    if (startPos <> 0) then
  452.    begin
  453.     delete(linia, 1, startPos + 9);
  454.     endPos := pos('.gif"', linia);
  455.     tytul := copy(linia, 1, endPos + 3); 
  456.     licznik := licznik + 1;
  457.     tytul := StringReplace(tytul, 'small/', '');
  458.     tytul := StringReplace(tytul, 'gif', 'jpg');
  459.     adres := tytul;
  460.     startPos := pos('alt="', linia);
  461.     delete(linia, 1, startPos + 4);
  462.     endPos := pos('">', linia);
  463.     tytul := copy(linia, 1, endPos - 1); 
  464.     PickTreeAdd(IntToStr(licznik) + tytul, adres);
  465.     end;
  466.    pozycja := pozycja + 1;
  467.    end;
  468.   until (pozycja >= pozycja2);
  469.   if licznik > 1 then
  470.    begin
  471.    if PickTreeExec(adres) then
  472.     GetPicture(adres, False);
  473.    end;
  474.   if licznik = 1 then 
  475.    GetPicture(adres, False);  
  476.   stronka.Free;
  477.  
  478.  
  479.   DisplayResults;
  480.   end;
  481.  
  482. begin
  483.   if CheckVersion(3,4,3) then
  484.     begin
  485.     MovieName := GetField(fieldOriginalTitle);
  486.     if MovieName = '' then
  487.       MovieName := GetField(fieldTranslatedTitle);
  488.     if Input('FilmWP Import', 'Podaj tytu│ filmu:', MovieName) then
  489.       begin
  490.       // Zamiana na ISO-8859-2
  491.       MovieName:=StringReplace(MovieName, '╣', chr(177));
  492.       MovieName:=StringReplace(MovieName, 'µ', chr(230));
  493.       MovieName:=StringReplace(MovieName, 'Ω', chr(234));
  494.       MovieName:=StringReplace(MovieName, '│', chr(179));
  495.       MovieName:=StringReplace(MovieName, '±', chr(241));
  496.       MovieName:=StringReplace(MovieName, '≤', chr(243));
  497.       MovieName:=StringReplace(MovieName, '£', chr(182));
  498.       MovieName:=StringReplace(MovieName, 'ƒ', chr(188));
  499.       MovieName:=StringReplace(MovieName, '┐', chr(191));
  500.       MovieName:=StringReplace(MovieName, 'Ñ', chr(161));
  501.       MovieName:=StringReplace(MovieName, '╞', chr(198));
  502.       MovieName:=StringReplace(MovieName, '╩', chr(202));
  503.       MovieName:=StringReplace(MovieName, 'ú', chr(163));
  504.       MovieName:=StringReplace(MovieName, '╤', chr(209));
  505.       MovieName:=StringReplace(MovieName, '╙', chr(211));
  506.       MovieName:=StringReplace(MovieName, 'î', chr(166));
  507.       MovieName:=StringReplace(MovieName, 'Å', chr(172));
  508.       MovieName:=StringReplace(MovieName, '»', chr(175));
  509.       AnalyzePage('http://film.wp.pl/p/szukaj.html', 'fromBox=1&szukaj='+MovieName+'&lista=a0');
  510.       end;
  511.     end
  512.   else
  513.     ShowMessage('Skrypt wymaga programu Ant Movie Catalog w wersji 3.4.3 lub nowszej');
  514. end.
  515.  
  516.  
  517.